package com.web.portal.service;

import java.util.EnumMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.web.portal.dao.BaseDao;
import com.web.portal.dao.LabPolicySearchType;
import com.web.portal.entity.LabPolicy;

@Service(value="labPolicyService")

public class DefaultLabPolicyService extends DefaultWebPortalService<LabPolicy> implements LabPolicyService{
private static final Logger LOG= Logger.getLogger(DefaultLabPolicyService.class);
	
	@Autowired
	@Qualifier (value="labPolicyDao")
	public void init(BaseDao dao){
		setBaseDao(dao);
	}
	public List<LabPolicy> getPolicy(LabPolicy labPolicy) {
		// TODO Auto-generated method stub
		LOG.debug("getting the LabPolicy...persisting the database........");
	return	getList(labPolicy);
	}

	public LabPolicy getLabPolicy(String id) {
		Map<LabPolicySearchType, Object> searchCriteria= new EnumMap(LabPolicySearchType.class);
		searchCriteria.put(LabPolicySearchType.ID, id);
		List<LabPolicy> result=searchByCriteria(searchCriteria);
		if(!(result.isEmpty()&& result.size()==1)){
			LOG.debug("unique Lab policy found");
			return result.get(0);
			
		}
		return null;
	}

	public void createOrSave(LabPolicy labPolicy) {
		// TODO Auto-generated method stub
		LOG.debug("Saving labPolicy.........................................");
		createOrUpdate(labPolicy);
		LOG.debug("Saved or Updated labPolicy successfully...........................");
	}

	@Override
	@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
	protected boolean isCreate(LabPolicy entity) throws RuntimeException {
		// TODO Auto-generated method stub
		return false;
	}

}
